﻿using IDAL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public  class BaseBLL<T,D>where T: BaseModel, new() where D:IBaseDAL<T>,new()
    {
        //侯海啸
        public D dal = new D();
        //添加
        public virtual int Add(T model)
        {

            dal.Add(model);
            return SaveChange();
        }
        //根据id删除
        public virtual int Delete(int id)
        {
            dal.Delete(id);
            return SaveChange();
        }
        //根据类删除
        public virtual int Delete(T model)
        {
            dal.Delete(model);
            return SaveChange();

        }
        //获取所有
        public virtual List<T> GetAll()
        {

            return dal.GetAll();
        }
        //获取单个
        public virtual T GetOne(int id)
        {
            return dal.GetOne(id);
        }
        //更新
        public virtual int Update(T model)
        {
            dal.Update(model);
            return SaveChange();
        }
        public virtual List<T> Search(Func<T, bool> where)
        {
            return dal.Search(where);
        }
        public virtual int GetCount(Func<T, bool> where)
        {
            return dal.GetCount(where);


        }
        public virtual List<T> Search(int pageSize, int pageIndex, bool isDesc, Func<T, bool> where)
        {
            return dal.Search(pageSize, pageIndex, isDesc, where);
        }
        public int SaveChange() {
            return dal.SaveChange();
        }
        public DbContextTransaction BeginTran()
        {
            
            return dal.BeginTran();

        }
    }
}
